﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Hangjing.SQLServerDAL;
using Hangjing.Common;
using Hangjing.Model;
using Hangjing.DBUtility;
using System.Collections.Generic;

public partial class Admin_oprecord_order : System.Web.UI.Page
{
    Record dal = new Record();

    protected string SqlWhere
    {
        get
        {
            return (ViewState["sqlWhere"] == null) ? "" : ViewState["sqlWhere"].ToString();
        }
        set
        {
            ViewState["sqlWhere"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
           
        }
    }

    public void GetData()
    {

        HJlog.toLog(SqlWhere);
        this.AspNetPager1.RecordCount = dal.GetCount(SqlWhere);
        rtpNewsList.DataSource = dal.GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, SqlWhere, "rid", 1);
        rtpNewsList.DataBind();
        AlertScript.RegScript(this.Page, this.UpdatePanel1, "init();");
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        GetData();
    }

    protected void DelList_Click(object sender, EventArgs e)
    {
        string IdList = this.hdDels.Value;
        int i = dal.DelList(IdList);
        if (i > 0)
        {
            AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:删除成功!','250','150','true','1000','true','text');init();");
            GetData();
        }
        else
        {
            AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:删除失败!','250','150','true','1000','true','text');init();");
            GetData();
        }
    }

    protected void rtpNewsList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int Id = Convert.ToInt32(e.CommandArgument);
        switch (e.CommandName)
        {
            case "del":
                if (dal.DelRecord(Id) > 0)
                {
                    AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:删除成功!','250','150','true','1000','true','text');init();");
                    GetData();
                }
                else
                {
                    AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:删除失败!','250','150','true','1000','true','text');init();");
                    GetData();
                }
                break;
        }
    }

    protected void btSearch_Click(object sender, EventArgs e)
    {
        SqlWhere = " 1=1 ";

        SqlWhere = new RightsTool().getOrderStateWhere(SqlWhere);


        if (tbKeyword.Text.Trim() != "")
        {
            SqlWhere += " and orderid = '" + WebUtility.InputText(tbKeyword.Text) + "'";
        }
        if (tbadmin.Text.Trim() != "")
        {
            SqlWhere += " and adminname like '%" + WebUtility.InputText(tbadmin.Text) + "%'";
        }
        

        if (tbstarttime.Text != "")
        {
            SqlWhere += " and  addtime > '" + WebUtility.InputText(this.tbstarttime.Text) + "' ";
        }
        if (tbendtime.Text != "")
        {
            SqlWhere += " and  addtime < '" + WebUtility.InputText(this.tbendtime.Text) + " 23:59:59' ";
        }



        if (tbTogoName.Text != "")
        {
            SqlWhere = SqlWhere + " and EXISTS (SELECT Points.Unid FROM dbo.Points left join Custorder on  Points.unid = Custorder.togoid WHERE orderid = dbo.Record.orderid AND Name LIKE '%" + WebUtility.InputText(tbTogoName.Text) + "%')";
        }
        if (tbdelivername.Text != "")
        {
            SqlWhere = SqlWhere + " and EXISTS (SELECT dataid FROM dbo.Deliver left join Custorder on  Deliver.dataid = Custorder.deliverid WHERE orderid = dbo.Record.orderid AND Name LIKE '%" + WebUtility.InputText(tbdelivername.Text) + "%')";

        }






        GetData();
    }


    protected void NewsSort_Changed(object sender, EventArgs e)
    {
        GetData();
    }
}
